plugins {
    id 'jacoco'
    id 'java'
    id 'application'
    id 'com.github.kt3k.coveralls' version '2.6.3'
    id 'maven'
    id "com.jfrog.bintray" version "1.8.4"
}

group 'com.github.romankh3'
version '4.4.0'
description 'Library that compares 2 images with the same sizes and shows the differences visually by drawing rectangles. ' +
        'Some parts of the image can be excluded from the comparison. Can be used for automation qa tests.'
sourceCompatibility = 1.8

mainClassName = "com.github.romankh3.image.comparison.ImageComparison"

repositories {
    mavenCentral()
}

dependencies {
    testCompile  'org.junit.jupiter:junit-jupiter-api:5.5.2'
    testCompile  'org.junit.jupiter:junit-jupiter-engine:5.5.2'
    testCompile 'org.mockito:mockito-core:2.26.0'
}

test {
    useJUnitPlatform()
}

jar {
    manifest {
        attributes 'Main-Class': mainClassName,
                "Implementation-Title": "image-comparison",
                "Implementation-Version": version,
                "Automatic-Module-Name": 'com.github.romankh3.image.comparison'
    }
}

jacocoTestReport {
    reports {
        xml.enabled = true // coveralls plugin depends on xml format report
        html.enabled = true
    }
}

defaultTasks << 'clean'
defaultTasks << 'build'

/* Publishing config */

task javadocJar(type: Jar) {
    classifier = 'javadoc'
    from javadoc
}

task sourcesJar(type: Jar) {
    classifier = 'sources'
    from sourceSets.main.allSource
}

artifacts {
    archives javadocJar, sourcesJar
}

// add all the info required by Maven Central to the pom
configure(install.repositories.mavenInstaller) {
    pom.project {
        inceptionYear '2020'
        name project.name
        packaging 'jar'
        description project.description

        url 'https://romankh3.github.io/image-comparison/'

        scm {
            connection 'git@github.com:romankh3/image-comparison.git'
            developerConnection 'git@github.com:romankh3/image-comparison.git'
            url 'https://github.com/romankh3/image-comparison'
        }

        licenses {
            license {
                name 'The Apache Software License, Version 2.0'
                url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
            }
        }

        developers {
            developer {
                id 'romankh3'
                name 'Roman Beskrovnyi'
                email 'roman.beskrovnyy@gmail.com'
            }
        }
    }
}

def getProjectProperty = { String propertyName ->
    project.properties[propertyName]
}

bintray {
    user = getProjectProperty "bintrayUserName"
    key = getProjectProperty "bintrayApiKey"
    configurations = ['archives']
    publish = true
    pkg {
        repo = 'image-comparison'
        name = 'image-comparison'
        licenses = ['Apache-2.0']
        labels = ['java', 'image', 'image-comparison']
        publicDownloadNumbers = true

        //noinspection GroovyAssignabilityCheck
        version {
            name = project.version
            vcsTag = project.version
            gpg {
                sign = true
            }
            mavenCentralSync {
                sync = true
                user = getProjectProperty 'ossrhUsername'
                password = getProjectProperty 'ossrhPassword'
                close = '1' // '0' to NOT close
            }
        }
    }
}

bintrayUpload.dependsOn build, sourcesJar
